import dayjs from 'dayjs'

// 日期格式化
export function formatDate(date: dayjs.ConfigType, format = 'YYYY-MM-DD HH:mm:ss') {
  return dayjs(date).format(format)
}

// 日期转时间戳
export function dateToTimestamp(
  dateStr: dayjs.ConfigType,
  isSeconds: boolean | number = false,
): number {
  const timestamp = dayjs(dateStr).valueOf()
  return isSeconds ? Math.floor(timestamp / 1000) : timestamp
}
